<template>
    <div class="tab-bar-item" @click="itemClick">
      <div v-if="!isActive">
        <slot name='item-icon'></slot>
      </div>
        <div v-else>
      <slot name='item-icon-active'></slot>
        </div>
      <div :style="activeStyle">
        <slot name='item-text'>
        </slot>
      </div>
    </div>
</template>

<script>
export default {
  name: 'tabbarItem',
  props: {
    path: String,
    activeColor: {
      type: String,
      default: 'red'
    }
  },
  data () {
    return {
      // isActive: true // 控制点击时颜色切换
    }
  },
  computed: {
    isActive () {
      // 找不到放回-1
      return this.$route.path.indexOf(this.path) !== -1
    },
    activeStyle () { // 处理颜色 过于复杂就放在计算属性里面
      return this.isActive ? { color: this.activeColor } : {}
    }
  },
  methods: {
    itemClick () {
      this.$router.push(this.path)
    }
  }
}
</script>

<style lang='scss' scoped>
 .tab-bar-item {
     flex:1;
     text-align: center ;
     height: 49px; //移动端高度默认49
    //  line-height: 49px;
   }
   img{
     width: 24px;
     height: 24px;
     vertical-align: middle;
     margin-bottom: 2px;
   }
   .active {
     color:red;
   }
</style>
